/*
 * Copyright (c) 2005, 2014 vacoor
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.vacoor.nothing.security.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.vacoor.nothing.web.entity.UuidEntity;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;

/**
 * @author vacoor
 * @Table T_ROLE
 */
@Entity
@Table(name = "T_ROLE")
@JsonIgnoreProperties({"permissions", "users"})
public class Role extends UuidEntity {
    /**
     * @Column
     */
    @NotNull
    @Size(min = 1)
    private String name;
    private String desc;
    private Boolean enabled = Boolean.FALSE;
    private List<Permission> permissions;
    private List<User> users;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Transient
    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    @Transient
    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    @ManyToMany
    @JoinTable(name = "T_ROLE_PERMISSION",
            joinColumns = {@JoinColumn(name = "ROLE_ID")},
            inverseJoinColumns = {@JoinColumn(name = "PERMISSION_ID")}
    )
    public List<Permission> getPermissions() {
        return permissions;
    }

    public void setPermissions(List<Permission> permissions) {
        this.permissions = permissions;
    }

    @ManyToMany(mappedBy = "roles")
    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }
}